from django import template
from djwheel.deprecated.siteconfig import siteconfig
register = template.Library()

@register.tag
def import_siteconfig_var(parser, token):
    """
    Usage::

    {% import_siteconfig_var %}
    param = '{{ siteconfig.param }}'

    Or::

    {% import_siteconfig_var as cfg %}
    param = '{{ cfg.param }}'

    """
    contents = token.split_contents()
    if len(contents) == 1:
        tag_name, varname = contents[0], 'siteconfig'
    elif len(contents) == 3 and contents[1] == 'as':
        tag_name, varname = contents[0], contents[2]
    else:
        raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents.split()[0]
    return SiteconfigNode(varname)

class SiteconfigNode(template.Node):
    def __init__(self, varname):
        self.varname = varname
    def render(self, context):
        context[self.varname] = siteconfig
        return ''
